package com.ewzj.bigdata.mvp.model;

import android.app.Application;

import com.ewzj.bigdata.app.GlobalHttpHandlerImpl;
import com.ewzj.bigdata.app.utils.Apputils;
import com.ewzj.bigdata.mvp.model.api.Api;
import com.ewzj.bigdata.mvp.model.api.service.CommonService;
import com.ewzj.bigdata.mvp.model.entity.resbean.BaseData;
import com.ewzj.bigdata.mvp.model.entity.resbean.BaseJson;
import com.ewzj.bigdata.mvp.model.entity.resbean.User;
import com.ewzj.bigdata.mvp.model.entity.resbean.UserBean;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.ewzj.bigdata.mvp.contract.MineContract;

import io.reactivex.Observable;
import io.reactivex.functions.Function;


@ActivityScope
public class MineModel extends BaseModel implements MineContract.Model {
    private Gson mGson;
    private Application mApplication;
    private CommonService service;
    @Inject
    public MineModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
        super(repositoryManager);
        this.mGson = gson;
        this.mApplication = application;
        this.service=repositoryManager.obtainRetrofitService(CommonService.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<UserBean> loadUserInfo() {
        return service.loadUserInfo()
                .map(new Function<BaseData<UserBean>, UserBean>() {
                    @Override
                    public UserBean apply(BaseData<UserBean> userBeanBaseData) throws Exception {
                        return userBeanBaseData.getData();
                    }
                });
    }
}